#pragma once

#include "EndGameDbCommon.h"

namespace EndGameDB
{

	// progress callback function pointers
	extern void (*OnBuildSubDbStartedPtr)(int wm, int wk, int bm, int bk, int wmrank, int bmrank);
	extern void (*PercentProgress)(int percent);
	extern void (*ProgressMessagePtr)(wchar_t* sMessage);
	extern void (*ProcessStartedPtr)(wchar_t* sProcessName);

	// message printing routine
	extern wchar_t MSG[1000];

	#define PRINT(msg, ...) {\
		swprintf_s(MSG, (size_t)1000, msg, __VA_ARGS__); \
		PrintMessage(MSG); \
	}

	 // Various helper macros
	///////////////////////////////////////////////////////////////////////////////////

	#define PROGRESS_DECLARE() int64 iPrgMax; register int64 iPrgStep; int64 iPrgIncr = 0; register int64 iPrgLastRep = 0; 

	#define PROGRESS_PARALLEL() iPrgMax, iPrgStep, iPrgIncr, iPrgLastRep, MSG, PercentProgress

	#define PROGRESS_INIT(STEP, MAX)  { \
		iPrgMax = MAX;  \
		iPrgStep = MAX * STEP / 100;  \
		iPrgIncr = 0; \
		iPrgLastRep = 0; \
	}

	#define HASH_SIGN #

	#define PROGRESS_CHECK(incr) if(incr >= iPrgLastRep + iPrgStep) 

#ifndef NO_PROGRESS	
		#define PROGRESS_WORK(incr) {\
				iPrgLastRep = incr; \
				int64 percent = incr * 100 / iPrgMax; \
				/*PRINT(L"%d%%", percent);*/ \
				if(PercentProgress != NULL) \
					PercentProgress((int)percent); \
		}	
#else
	#define PROGRESS_WORK
#endif

	#define PROGRESS_REPORT(HASH, incr) { \
			pragma omp critical \
			{\
			}\
		} \
	}

	#define PROCESS_STARTED(name, ...) { \
		if(ProcessStartedPtr != NULL) \
		{ \
			swprintf_s(MSG, (size_t)1000, name, __VA_ARGS__); \
			ProcessStartedPtr(MSG); \
		}\
	}

	#define SAVE_STATE() (SaveDBState<BitsPerRow, MaxField>(wm, wk, bm, bk, wmrank, bmrank, currentDb_w, currentDb_b, dtm_W, dtm_B, state));

	void PrintMessage(wchar_t *sMessage);


	// global EngineData structure for bitboard move generator
	extern SEngineData* g_ED;
}
